package com.ztom.daily.n2022.m4;

/**
 * 写字符串需要的行数
 * <p>
 * https://leetcode-cn.com/problems/number-of-lines-to-write-string/
 *
 * @author ZhangTao
 */
public class Day12NumberOfLines {

    public int[] numberOfLines(int[] widths, String s) {
        // 记录行数
        int line = 1;
        //  记录当前行的宽度
        int width = 0;
        for (int i = 0; i < s.length(); i++) {
            int need = widths[s.charAt(i) - 'a'];
            width += need;
            if (width > 100) {
                line++;
                // 换行了
                width = need;
            }
        }
        return new int[]{line, width};
    }
}
